#ifndef __SERVORATE_H__
#define __SERVORATE_H__ 1

#include "Arduino.h"
#include "Servo.h"
#include "Protothread.h"
#include "ThreadMicroDelay.h"

#define DELAY_SERVO_AIRTRONICS_94102 4500
#define DELAY_SERVO_CIRRUS_CS_10BB 2250

class ThreadServoRate: public Protothread
{
public:
  ThreadServoRate( int nPin, unsigned long nMaxServoSpeedInMicrosPerDegree,
                   unsigned int nInitialPosition,
                   unsigned int nInitialRateInDegPerSec );

  virtual ~ThreadServoRate();

  unsigned int getPosition();

  void setPosition( int nTargetPosition, int nMoveRateInDegPerSec );

  boolean isMoving();

  virtual bool run();

protected:
  Servo obj;
  unsigned int nCurPosition;
  unsigned int nTargetPosition;
  unsigned long nLastMoveTimestampInMicros;
  unsigned long nMaxServoSpeedInMicrosPerDegree;
  unsigned int nMoveRateInDegPerSec;
  ThreadMicroDelay threadMicroDelay;
};

#endif // __SERVORATE_H__
